import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'
import GoodDetail from '../views/GoodDetail.vue'
import GoodCart from '../views/GoodCart.vue'
import Order from '../views/Order.vue'
import User from '../views/User.vue'
import Main from '../views/Main.vue'
import SearchDetail from '../views/SearchDetail.vue'
import SearchByType from '../views/SearchByType.vue'


Vue.use(VueRouter)

const routes = [

  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  //主页
  {
    path: '/',
    name: 'Main',
    component: Main
  },
  // 按照分类进行搜索
  {
    path: '/searchByType',
    name: 'SearchByType',
    component: SearchByType
  },

  //搜索详情页
  {
    path: '/searchdetail',
    name: 'SeahchDetail',
    component: SearchDetail
  },

  //商品详情页
  {
    path: '/GoodDetail',
    name: 'GoodDetail',
    component: GoodDetail
  },

  //购物清单页
  {
    path: '/GoodCart',
    name: 'GoodCart',
    component: GoodCart
  },

    //商品详情页
    {
      path: '/UserOrder',
      name: 'UserOrder',
      component: Order
  },
    
    
    //个人管理页面
  {
    path: '/User',
    name: 'User',
    component: User
    },

  

  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/About.vue')
    }
  }
]

const router = new VueRouter({
  routes
})


// //路由拦截
// router.beforeEach((to, from, next) => {
//   //获取token
//   let token = sessionStorage.getItem("token");

//   //判断token

//   if (token) {
//     next();
//   } else {
//     if (to.path === '/login') {
//       next()
//     }

//     else {
//       next("/login")
//     }

//   }
// })

export default router
